from selenium import webdriver
from selenium.webdriver.common.by import By
import time
# 选中要导的模块,使用快捷键:ALT +Enter
class BrowserOperation:
    def __init__(self):
        self.driver = webdriver.Chrome()
        self.driver.get('http://www.baidu.com')

    def quit(self, seconds=2):
        time.sleep(seconds)
        self.driver.quit()

    def window_size(self):
        # 浏览器窗口大小设置
        # 设计具体的尺寸
        for i in range(3):
            time.sleep(2)
            self.driver.set_window_size(480, 800)

            #浏览器最大化
            time.sleep(2)
            self.driver.maximize_window()

            # 浏览器最小化
            time.sleep(2)
            self.driver.minimize_window()

    def forward_and_back(self):
        # 浏览器前进和后退
        for i in range(3):
            # 后退
            time.sleep(2)
            self.driver.back()

            # 前进
            time.sleep(2)
            self.driver.forward()

    def refresh(self):
        # 浏览器刷新
        time.sleep(2)
        self.driver.refresh()

    def close(self):
        # close 关闭标签页
        # 获取新闻链接标签-链接文本定位方式
        time.sleep(2)
        news = self.driver.find_element(By.LINK_TEXT, '新闻')
        news.click()
        # 关闭当前页-百度首页
        time.sleep(2)
        self.driver.close()

if __name__ == '__main__':
    browser = BrowserOperation()
    browser.window_size()
    browser.forward_and_back()
    browser.refresh()
    browser.close()
    browser.quit()